package com.lenovo.lcdm.dcm.common.util;



import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证工具类
 *
 * @author zhangjian
 * @date 2019-08-29 16:10:00
 */
public class ValidateUtil {

    public static boolean checkEmail(String email) {
        String ruleEmail = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
        boolean flag = false;
        if (!StringUtils.isEmpty(email)) {
            flag = Pattern.matches(ruleEmail, email);
        }
        return flag;
    }

    /**
     * 校验Name - 大小写英文，数字，下划线，中间空格
     * @param name
     * @return
     */
    public static boolean checkName(String name) {
        if (name == null || name.isEmpty()) {
            return false;
        }
        String regex = "([a-z]|[A-Z]|[0-9]|_| )*";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(name);
        return matcher.matches();
    }
}
